﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Data;

namespace DuncanDAL
{
    public class PayRecordsDataService : IDAL<T_PayRecordsObject>
    {
        public const string SQL_SELECT_PayRecords = "select * from T_PayRecords";
        public const string SQL_INSERT_PayRecords = "insert into T_PayRecords(PayDate,PayItem,"+
            " PayObject,PayCategoryOID,PayNecessity,PaySum,PayMemo) "+
            " values('{0}','{1}',{2},{3},{4},{5},'{6}')";

        public const string SQL_DEKETE_PayRecords = "delete from T_PayRecords where OID={0}";

        public const string SQL_UPDATE_PayRecords = "update T_PayRecords set"+
            " PayDate = '{0}',PayItem='{1}',PayObject={2},"+
            " PayCategoryOID={3},PayNecessity={4},PaySum={5},PayMemo='{6}' "+
            " where OID={7}";
        #region IDAL<T_PayRecordsObject> 成员

        public void Create(T_PayRecordsObject obj)
        {
            string sql = string.Format(SQL_INSERT_PayRecords, obj.Db_PayDate, obj.Db_PayItem, obj.Db_PayObject, obj.Db_PayCategoryOID, obj.Db_PayNecessity, obj.Db_PaySum, obj.Db_PayMemo);
            DBHelper.Excute(sql);
        }

        public void Delete(T_PayRecordsObject obj)
        {
            DBHelper.Excute(string.Format(SQL_DEKETE_PayRecords, obj.Db_OID));
        }

        public void Update(T_PayRecordsObject obj)
        {
            string sql = string.Format(SQL_UPDATE_PayRecords, obj.Db_PayDate, obj.Db_PayItem, obj.Db_PayObject, obj.Db_PayCategoryOID, obj.Db_PayNecessity, obj.Db_PaySum, obj.Db_PayMemo,obj.Db_OID);
            DBHelper.Excute(sql);
        }

        public IList<T_PayRecordsObject> QueryAll()
        {
            IList<T_PayRecordsObject> list = new List<T_PayRecordsObject>();
            DataTable dtT_PayRecords = new DataTable("T_PayRecords");
            DBHelper.FillData(SQL_SELECT_PayRecords, dtT_PayRecords);
            foreach (DataRow item in dtT_PayRecords.Rows)
            {
                T_PayRecordsObject o = new T_PayRecordsObject();
                o.Data2Object(item);
                list.Add(o);
            }



            return list;
        }

        public T_PayRecordsObject Get(object id)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
